package com.itmuch.contentcenter.sentineltest;

import com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

/**
 * @author caiqian
 * @date 2021/5/8 16:21
 */
//@Component
public class MyRequestOriginParser implements RequestOriginParser {

  @Override
  public String parseOrigin(HttpServletRequest httpServletRequest) {
    String origin = httpServletRequest.getParameter("origin");

    if (StringUtils.isBlank(origin)) {
      throw new IllegalArgumentException("origin must be specified!");
    }

    return origin;
  }
}
